package com.tudouji.project.store.controller;

import java.util.List;

import org.springframework.remoting.jaxws.AbstractJaxWsServiceExporter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.store.domain.Stockunit;
import com.tudouji.project.store.service.IStockunitService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 库存单位Controller
 * 
 * @author tudouji
 * @date 2021-01-06
 */
@RestController
@RequestMapping("/store/stockunit")
public class StockunitController extends BaseController
{
    @Autowired
    private IStockunitService stockunitService;

    /**
     * 查询库存单位列表
     */
    @PreAuthorize("@ss.hasPermi('store:stockunit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Stockunit stockunit)
    {
        startPage();
        List<Stockunit> list = stockunitService.selectStockunitList(stockunit);
        return getDataTable(list);
    }

    /**
     * 导出库存单位列表
     */
    @PreAuthorize("@ss.hasPermi('store:stockunit:export')")
    @Log(title = "库存单位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Stockunit stockunit)
    {
        List<Stockunit> list = stockunitService.selectStockunitList(stockunit);
        ExcelUtil<Stockunit> util = new ExcelUtil<Stockunit>(Stockunit.class);
        return util.exportExcel(list, "stockunit");
    }

    /**
     * 获取库存单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:stockunit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stockunitService.selectStockunitById(id));
    }

    /**
     * 新增库存单位
     */
    @PreAuthorize("@ss.hasPermi('store:stockunit:add')")
    @Log(title = "库存单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Stockunit stockunit)
    {
        return toAjax(stockunitService.insertStockunit(stockunit));
    }

    /**
     * 修改库存单位
     */
    @PreAuthorize("@ss.hasPermi('store:stockunit:edit')")
    @Log(title = "库存单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Stockunit stockunit)
    {
        return toAjax(stockunitService.updateStockunit(stockunit));
    }

    /**
     * 删除库存单位
     */
    @PreAuthorize("@ss.hasPermi('store:stockunit:remove')")
    @Log(title = "库存单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockunitService.deleteStockunitByIds(ids));
    }

    @GetMapping("/findStockUnitList")
    public AjaxResult findStockUnitList(Stockunit stockunit)
    {
        List<Stockunit> list = stockunitService.selectStockunitList(stockunit);
        return AjaxResult.success(list);
    }
}
